/**
 * 进度管理
 */
export default class ProcessManager{
    private nextId:number=0;
    private processList=new Map<number,Process>()
    constructor(){}

    add(p:Process){
        const id=this.nextId;
        this.nextId++;
        this.processList.set(id,p);
        return id;
    }

    remove(id:number){
        let p=this.processList.get(id);
        if(p){
            p.onChange();
        }
        return this.processList.delete(id);
    }

    list(){
        return Array.from(this.processList.entries());
    }

    count(){
        return this.processList.size;
    }
}

export interface Process{
    name:string,
    /**
     * 进度，0－100，如果无法显示进度就用NAN吧。
     */
    rate:number,
    onChange:()=>void;
}